/*
 * Copyright (c) 2016. For Intelligent Group.
 */

package com.intelligent.mts.client;


import com.intelligent.mts.client.core.view.MainPanel;
import com.intelligent.mts.client.core.view.MainTabbed;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import javax.swing.*;
import java.awt.*;

/**
 * Created by Peter on 2016/7/6.
 */
@org.springframework.stereotype.Component
public class MainFrame extends JFrame {

    @Autowired
    private MainTabbed mainTabbed;

    @Autowired
    private MainPanel mainPanel;

    @Autowired
    private com.intelligent.mts.client.core.view.Main main;


    private void initComponents() {
        this.setTitle("OBC-MTS");
    }

    @PostConstruct
    public void init() {
        initComponents();

        MainFrame frame = this;
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                frame.setLocationRelativeTo(null);
//                frame.setPreferredSize(new Dimension(1000, 600));
                frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                frame.getContentPane().add(main);
                frame.pack();
                frame.checkShowPoint();
                frame.setVisible(true);
            }
        });
    }

    private void checkShowPoint() {
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        int screenWidth = screenSize.width / 2;
        int screenHeight = screenSize.height / 2;
        int height = this.getHeight();
        int width = this.getWidth();
        this.setLocation(screenWidth - width / 2, screenHeight - height / 2);
    }
}
